import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'
import './plugins/iview.js'
import './plugins/codemirror'

axios.defaults.baseURL = ''
// 设置拦截器，添加请求头
axios.interceptors.request.use(config => {
  config.headers.Token = window.sessionStorage.getItem('token')
  return config
})
// 设置拦截器处理后台的返回状态
axios.interceptors.response.use(function (response) {
  if (response.data === '000401') {
    router.push('/login')
  }
  return response
}, function (error) {
  console.log('vue响应拦截器异常' + error)
  return error
})
Vue.prototype.http = axios
Vue.config.productionTip = false
Vue.prototype.dateFormat = function (time) {
  const datetime = new Date(time)
  const year = datetime.getFullYear()
  const month = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1
  const date = datetime.getDate() < 10 ? '0' + datetime.getDate() : datetime.getDate()
  const hour = datetime.getHours() < 10 ? '0' + datetime.getHours() : datetime.getHours()
  const minute = datetime.getMinutes() < 10 ? '0' + datetime.getMinutes() : datetime.getMinutes()
  const second = datetime.getSeconds() < 10 ? '0' + datetime.getSeconds() : datetime.getSeconds()
  return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second
}

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
